
import dataclasses
import enum
from transformers import HfArgumentParser,IntervalStrategy
class myArgumentParser(HfArgumentParser):

    
    def parse_dict(self, args, allow_extra_keys: bool = False) :
        """
        Alternative helper method that does not use `argparse` at all, instead uses a dict and populating the dataclass
        types.

        Args:
            args (`dict`):
                dict containing config values
            allow_extra_keys (`bool`, *optional*, defaults to `False`):
                Defaults to False. If False, will raise an exception if the dict contains keys that are not parsed.

        Returns:
            Tuple consisting of:

                - the dataclass instances in the same order as they were passed to the initializer.
        """
        unused_keys = set(args.keys())
        outputs = []
        for dtype in self.dataclass_types:
            keys = {f.name:f.type for f in dataclasses.fields(dtype) if f.init }
            inputs = []
            for k, v in args.items():
                if k in keys:
                    if k=='save_strategy':
                        print('kkk',keys[k])
                    if keys[k]==str or keys[k]==IntervalStrategy:
                        inputs.append(f'\t{k} = \'{v}\'')
                    else:
                        inputs.append(f'\t{k} = {v}')
            # unused_keys.difference_update(inputs.keys())
            out='TrainingArguments('
            for i in inputs:
                out+=f'\n{i},'
            out+='\n)'
            print(out)
        return out

